package com.acme.bankapp.domain.bank.client;

import com.acme.bankapp.domain.bank.account.Account;

import java.io.Serializable;

/**
 * This class represents bank client
 *
 * @author Alexander Kotov
 */
public class Client implements Serializable {
    private String name;
    private Gender gender;
    private Account account;
    private String emailAddress;

    public Client(String name, Gender gender, String emailAddress) {
        super();
        this.name = name;
        this.gender = gender;
        this.emailAddress = emailAddress;
    }

    public Client(String name, Gender gender, String emailAddress, Account account) {
        this(name, gender, emailAddress);
        this.account = account;
    }

    public String getName() {
        return name;
    }

    public Gender getGender() {
        return gender;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

//    public void setAccount(Account account) {
//        this.account = account;
//    }

    /**
     * @return client's {@linkplain Account account}
     */
    public Account getAccount() {
        return account;
    }

    /**
     * @return client's gender and name
     */
    public String getClientSalutation() {
        return gender.getSalutation() + " " + name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Client client = (Client) o;

        if (gender != client.gender) {
            return false;
        }

        if (name != null) {
            if (!name.equals(client.name)) {
                return false;
            }
        } else if (client.name != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = 0;
        if (name != null) {
            result = name.hashCode();
        }
        int genderHashCode = 0;
        if (gender != null) {
            genderHashCode = gender.hashCode();
        }
        result = 31 * result + genderHashCode;
        return result;
    }

    @Override
    public String toString() {
        return getClientSalutation();
    }
}
